/* pfs03ChatMessage.cpp
 *
 * --
 * Copyright (c) 2012, Christophe Huriaux
 * Distributed under the terms of the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * --
 */

#include <packet/pfs03ChatMessage.h>
#include <wrapper/JavaStreamWrapper.h>

pfs03ChatMessage::pfs03ChatMessage()
    : McPacketFromServer(0x03), message("")
{
}

unsigned int pfs03ChatMessage::length()
{
    return 1 + 2 + message.length();
}

int16_t pfs03ChatMessage::setField(uint8_t field, void* value)
{
    static int16_t slen;

    switch (field)
    {
        case 0:
        default: return 2;
        case 1: slen = JavaStreamWrapper::readShort(value); return 2*slen;
        case 2: message = JavaStreamWrapper::readUTF(value, slen); return -1;
    }
}

std::string pfs03ChatMessage::getMessage()
{
    return message;
}


